﻿using System;
using System.Data.Linq;
using System.IO;
using System.Windows.Data;
using System.Windows.Media.Imaging;
using LASDesktop.LASDBClasses;

namespace LASDesktop.Classes
{
    public class ImageConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                var bitImg = new BitmapImage();
                bitImg.BeginInit();
                var ms = new MemoryStream((value as EntitySet<Foto>)[0].Foto1.ToArray());
                bitImg.StreamSource = ms;
                bitImg.EndInit();
                return bitImg;
            }
            catch
            {
                return "..\\Graphics\\ImageError.png";
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

    }
}
